/*
*	File: Quaternion.cpp
*	Date: 12/06/2011
*	Author: Ivan Gao
*	Desc:
*/
#ifndef QUATERNION_H_
#define QUATERNION_H_
#include "Vector.h"
#include "CommonDef.h"
#include <string.h>
class SIMPLEANIMATION_API SQuaternion
{
public:
	union
	{
		struct 
		{
			float x, y, z, w;
		};
		struct  
		{
			float v[4];
		};
	};
public:
	SQuaternion ();
	SQuaternion (float _x, float _y, float _z, float _w);
	SQuaternion (const SQuaternion & rQua);
	~SQuaternion ();

	float operator [] (int nIdx);
	float operator [] (int nIdx) const;
	SQuaternion & operator = (const SQuaternion & rQua);
	SQuaternion & operator *= (const SQuaternion & rQua);
	SQuaternion & operator += (const SQuaternion & rQua);
	SQuaternion & operator -= (const SQuaternion & rQua);
	SQuaternion & operator *= (const SVector3);
	SQuaternion & operator *= (float scale);
	SQuaternion & operator /= (float scale);
	SQuaternion & SQuaternion::operator *= (const SVector3 & rVector);
	bool operator == (const SQuaternion & rQua) const;
	bool operator != (const SQuaternion & rQua) const;
	SQuaternion & SphericalInterpolation (float d, const SQuaternion & rQua);
	inline void Clear ()
	{
		memset (v, 0, sizeof(v));
	}

	SQuaternion & Conjugate ();
	SQuaternion & Invert ();
	inline void Set (float _x, float _y, float _z, float _w)
	{
		x = _x;
		y = _y;
		z = _z;
		w = _w;
	} // Set

	inline void Set (float * pV)
	{
		memcpy ((void *)v, pV, sizeof(v));
	}
}; // SQuaternion
SQuaternion SIMPLEANIMATION_API operator * (const SQuaternion & q, const SQuaternion & r);
SQuaternion SIMPLEANIMATION_API CrossProduct (const SQuaternion & q, const SQuaternion & r);
float SIMPLEANIMATION_API DotProduct (const SQuaternion & q, const SQuaternion & r);
#endif // QUATERNION_H_